package com.huo.com.redisLock.web;

import com.huo.com.redisLock.lock.TestLock;
import com.huo.com.redisLock.service.TestStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.UUID;


@RestController
public class TestRedisLockController  {

     @Autowired
     private TestStockService testStockService;

     @Autowired
     private RedisTemplate<String,String> redisTemplate;


     //获取仓库
     @RequestMapping("/stock/get")
     private Object getStock(@RequestBody Map<String,String> param){

         String string = UUID.randomUUID().toString();
         param.put("userId",string);
         testStockService.getStock(param);

         return "OK";
     }


     @RequestMapping("unlock")
     public void test(){
          TestLock testLock=new TestLock(redisTemplate);

         boolean unLock = testLock.unLock("100", "555");
         System.out.println(unLock);
     }

}
